Skip to content

Translate transient WriteConflict to ConcurrencyFailureException#5195

Open
seonwooj0810 wants to merge 1 commit into
spring-projects:mainfrom
seonwooj0810:issue/5150
Open

Translate transient WriteConflict to ConcurrencyFailureException#5195
seonwooj0810 wants to merge 1 commit into
spring-projects:mainfrom
seonwooj0810:issue/5150

Conversation

@seonwooj0810
Copy link
Copy Markdown

WriteConflict (code 112) returned with a `TransientTransactionError` label is
a retryable concurrency failure, but `MongoExceptionTranslator` mapped it to
`DataIntegrityViolationException` — a `NonTransientDataAccessException` —
which silently breaks retry policies keyed on Spring's exception hierarchy.

This change checks `isTransientFailure(ex)` before falling through to
`DataIntegrityViolationException` and returns `ConcurrencyFailureException`
(a `TransientDataAccessException`) instead. The check is applied in both
the `DATA_INTEGRITY_EXCEPTIONS` branch (real `MongoWriteException`) and the
`isDataIntegrityViolationError` fall-through branch (plain `MongoException`
carrying a data-integrity error code).

Scope note: `MongoBulkWriteException` continues to return
`BulkOperationException` because bulk failures require per-write inspection
and were deemed out of scope for this fix.

Closes #5150

When a MongoException carries a TransientTransactionError label, return
ConcurrencyFailureException (a TransientDataAccessException) instead of
DataIntegrityViolationException so retry policies keyed on Spring's
exception hierarchy can react accordingly. Applied in both the
DATA_INTEGRITY_EXCEPTIONS branch and the isDataIntegrityViolationError
fall-through branch.

Closes spring-projects#5150

Signed-off-by: seonwooj0810 <seonwooj0810@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MongoDB error code 112 (WriteConflict) is translated to DataIntegrityViolationException, even when the driver marks it as retryable.

2 participants